package chapter26;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

// 线程作业--输出问候语和学生信息
public class ThreadJob {
    public static void main(String[] args) {
        Student stu1 = new Student(6666,"胖虎");
        Student stu2 = new Student(7777,"小虎");
        Student stu3= new Student(8888,"大熊");
        Student[] stus = {stu1,stu2,stu3};
        Runnable printStudent = new StudentFo(stus);
        ExecutorService executor = Executors.newFixedThreadPool(3);
        executor.execute(new PrintGreetings("hello java", 50));
        executor.execute(new Thread(printStudent));
        executor.execute(new PrintGreetings("goodbye java", 50));
        executor.shutdown();// 关闭线程池
    }
}
class PrintGreetings implements Runnable {
    private String stringToPrint; // 要打印的字符
    private int times; //重复的时间

    public PrintGreetings(String c, int t) {
        stringToPrint = c;
        times = t;
    }
    @Override
    public void run() {
        for (int i = 0; i < times; i++) {
            System.out.println(stringToPrint);
        }
    }
}
class StudentFo implements Runnable{
    Student[] students;
    public StudentFo(Student[] students){
        this.students=students;
    }
    @Override
    public void run() {
        for(Student s:students){
            System.out.println(s);
        }
    }
}